/*
	Copyright (C) 2010 Salil Bhagurkar

	This file is part of k3

	k3 is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	k3 is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with k3.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <shared.h>

/**
Parse a path and assign it to the fs variable specified
*/
int fsiter_parse(struct fs **fs, const char *path)
{
	dprint(D_FREQ, "", path);
	struct fs *reset;
	reset = *fs;
	*fs = fsparse_get_relative(*fs, path);
	if(!(*fs)) {
		*fs = reset;
		return ENOREG;
	}
	return 0;
}

/**
Go to the first child of the fs node
*/
int fsiter_get_child(struct fs **fs)
{
	dprint(D_FREQ, (*fs)->name, "");
	struct fs *reset;
	reset = *fs;
	fsres_child_enumerators(*fs);
	*fs = (*fs)->links;
	if(!(*fs)) {
		*fs = reset;
		return ESTATEINV;
	}
	return 0;
}

/**
Go to the parent of the fs node
*/
int fsiter_get_parent(struct fs **fs)
{
	dprint(D_FREQ, (*fs)->name, "");
	struct fs *reset;
	reset = *fs;
	*fs = (*fs)->parent;
	if(!(*fs)) {
		*fs = reset;
		return ESTATEINV;
	}
	return 0;
}

/**
Go to the next child of the parent fs node
*/
int fsiter_get_next(struct fs **fs)
{
	dprint(D_FREQ, (*fs)->name, "");
	struct fs *reset;
	reset = *fs;
	*fs = (*fs)->next;
	if(!(*fs)) {
		*fs = reset;
		return ESTATEINV;
	}
	return 0;
}
